import requests


class TpshopRegisterApi(object):
    # 创建Session实例
    session = requests.Session()

    # 发送验证码请求
    @classmethod
    def get_verify(cls):
        # 使用Session实例调用get方法，发送获取验证码请求(不需要获取cookie)
        cls.session.get(
            "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify&type=user_reg&r=0.582699894399026")

    # 发送登录请求
    @classmethod
    def register(cls, register_data):
        # 使用同一个Session实例post发送登录请求url、请求头、请求体  不需要携带cookie，得到响应结果
        url = "http://hmshop-test.itheima.net/index.php/Home/user/reg.html"
        resp = cls.session.post(url=url, data=register_data)
        return resp


# if __name__ == '__main__':
#     TpshopRegisterApi.get_verify()
#     register_data = {
#         "username": "13012345678",
#         "verify_code": "8888",
#         "password": "123456",
#         "password2": "123456",
#         "invite_phone": "13012345678"
#     }
#     resp = TpshopRegisterApi.register(register_data)
#     print(resp.json())
